﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Skynet.BusinessEntities;
using System.ServiceModel;

namespace Skynet.BusinessLogic.BusinessComponents
{
    public partial class BCExamQueries 
    {
        
        public IEnumerable<BaseQuestion> SearchQuestion(QuestionSearchOptions options = QuestionSearchOptions.GetAll, Guid? QuestionId = null, Guid? CustomerExamId = null, Guid? ExamId = null)
        {
            List<BaseQuestion> Result = new List<BaseQuestion>();
            switch (options)
            {
                case QuestionSearchOptions.GetOne:
                    break;
                case QuestionSearchOptions.RuntimeByCustomerExamId:
                    var questions = this.QuestionRepository.RuntimeByCustomerExamId(CustomerExamId.Value);
                    var random = new Random();
                    foreach (var item in questions)
                    {
                        item.Alternatives = this.AlternativeRepository.RuntimeAlternativesByQuestionId(item.CustomerQuestionId);
                    }
                    Result = questions;
                    break;
                case QuestionSearchOptions.FullGetOneWithAlternatives:

                    break;
                case QuestionSearchOptions.GetAll:


                case QuestionSearchOptions.DesignOneWithAlternatives:
                    var qwa = this.QuestionRepository.GetDesignQuestion(QuestionId.Value);
                    qwa.Alternatives = this.AlternativeRepository.DesignAlternativesByQuestionId(QuestionId.Value);
                    Result.Add(qwa);
                    break;
                case QuestionSearchOptions.DesignViewWithAlternativesByExamId:
                    var qwabe = this.QuestionRepository.DesignQuestionsByExamId(ExamId.Value);
                    foreach (var item in qwabe)
                    {
                        item.Alternatives = this.AlternativeRepository.DesignAlternativesByQuestionId(item.Id);
                        Result.Add(item);
                    }

                    break;
                default:
                    break;
            }
            return Result;
        }

        
        public string QueryQuestions(QueryQuestionsOptions options = QueryQuestionsOptions.DesignByExamView, Guid? ExamId = null)
        {
            string result = string.Empty;  
            switch (options)
            {
                case QueryQuestionsOptions.DesignByExamView:
                    result = this.XmlDataQueriesService.executeprocedure(Constants.OperationsNames.Questions.DesignQuestionsView, ExamId);
                    break;
                default:
                    break;
            }
            return result;  
        }
    }
}
